const api = require('../../../api/mop_api');
import { log, err } from '../../../utils/wxapi';

Page({
  /**
   * 页面的初始数据
   */
  data: {
    // 默认显示 日
    topNav: 0,
    nav: ['日', '月', '年'],
    date: '',
    day: {},
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    // const now = new Date();
    // const year = now.getFullYear();
    // const month = now.getMonth() + 1;
    // const day = now.getDate();
    // this.setData({ date: `${year}-${month}-${day}` })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // this.day()
  },
  async day() {
    try {
      const staDate = this.data.date;
      const res = await api.daydata({ staDate });
      if (res.respCode === 200) {
        const day = JSON.parse(res.source);
        this.setData({ day });
      }
    } catch (error) {
      err(error);
      throw error;
    }
  },
  getTopNav(e) {
    let topNav = e.target.dataset.id;
    this.setData({ topNav });
  },
  bindDateChange(e) {
    const date = e.detail.value;
    log(date);
    this.setData({ date });
    this.day();
  },
  month() {
    let data = JSON.stringify({
      year: '2023',
      month: '06',
    });
    api.monthdata(data).then(res => {
      let day = JSON.parse(res.data.source);
      log(day);
    });
  },
  year() {
    let data = JSON.stringify({
      year: '2023',
    });
    api.yeardata(data).then(res => {
      let day = JSON.parse(res.data.source);
      log(day);
    });
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
